package top.resty.erp.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import top.resty.erp.domain.OutStorage;
import top.resty.erp.domain.Storage;

import java.util.List;

/**
 * <pre>
 *
 * </pre>
 *
 * @author : resty
 * @date : 2021年04月01 15:32
 */
@Mapper
public interface IOutStorage {
	
	@Select({"<script>", "select id,out_id outId,user_id userId,out_date outDate ,variety_name varietyName,type_name typeName,standard_name standardName,price,count,money,transport,pay_condition paCondition" + "from tb_out_storage where 1= 1", "<if test = 'storage.variety != null and storage.variety !=\"\"'>and variety = #{storage.variety}</if>", "<if test = 'storage.type != null and storage.type !=\"\"'>and type = #{storage.type}</if>", "<if test = 'storage.standard != null and storage.standard !=\"\"'>and standard = #{storage.standard}</if>", "</script>"})
	public List<OutStorage> findOutStorageByCondition(@Param("storage") Storage storage);
	
	@Select({"<script>",
			"select id,out_id outId,user_id userId,out_date outDate ,variety_name varietyName,",
			"type_name typeName,standard_name standardName,price,count,money,transport,pay_condition paCondition from",
			"tb_out_storage where 1=1 " +
					"<if test='outId != null and outId != \"\"'> and out_id = #{outId}</if>",
			"</script>"})
	public List<OutStorage> findOutStoragesByOutId(@Param("outId") String outId);
	
	
	@Insert({"<script>", "insert into tb_out_storage values", "<foreach  collection='storages' item='item' index='index' separator=','>", "(null,#{item.outId},#{item.userId},#{item.managerId},#{item.outDate},#{item.varietyName},#{item.typeName}," + "#{item.standardName},#{item.price},#{item.count},#{item.money},#{item.transport},#{item.payCondition})", "</foreach>", "</script>"})
	public int saveOutStorages(@Param("storages") List<OutStorage> storages);
	
}
